package com.xwj.java8.test;

import com.xwj.java8.utils.SortedUtils;
import lombok.Data;

import java.util.List;
import java.util.SortedMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.Collections.reverseOrder;

/**
 * @author: xwj
 * @date: 2021/3/10 10:01
 * description: 测试排序工具类
 */
public class SortedMain {
    @Data
    public static class Node{
        private Integer score;
        private String name;
        private Integer ranking;

        public Node(Integer score, String name) {
            this.score = score;
            this.name = name;
        }
    }


    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        List<Node> nodes = Stream.iterate(1, n -> n + 1)
                .limit(1000000)
                .map(it -> new Node(it, it + ""))
                .collect(Collectors.toList());
        SortedMap<Integer, List<Node>> rank = SortedUtils.ranking(nodes.stream(), Node::getScore, reverseOrder());

        List<Node> extracted = SortedUtils.convert(rank, Node::setRanking);
        long end = System.currentTimeMillis();
        System.out.println("转换耗时：" + (end - start));
        extracted.forEach(it -> System.out.println(1));
        System.out.println("打印耗时：" + (System.currentTimeMillis() - end));
    }
}
